
import 'package:flutter/material.dart';
import 'package:riki_login/api/h5_route/api.dart';
import 'package:riki_login/config/global.dart';
import 'package:riki_login/res/colors.dart';
import 'package:riki_login/res/header.dart';
import 'package:riki_webview/riki_webview.dart';
import 'package:riki_base_flutter/riki_base_flutter.dart';
import '../../../r.dart';
import 'package:riki_webview/entity/riki_webview_config.dart';

import '../../../riki_login.dart';
///作者：范玉辉
///创建时间：2020/12/15
///说明：APP 2.0 隐私协议
class LoginPrivacyWidget extends StatefulWidget {
  bool isAgreement;
  IsAgreementFun isAgreementFun;

  LoginPrivacyWidget(this.isAgreement, this.isAgreementFun);

  @override
  _LoginPrivacyWidgetState createState() => _LoginPrivacyWidgetState();
}

class _LoginPrivacyWidgetState extends State<LoginPrivacyWidget> {
  @override
  Widget build(BuildContext context) {
    double? height;
    EdgeInsets padding = EdgeInsets.symmetric(vertical: 2.w);
    return GestureDetector(
      onTap: () {
        _onPressAgreement();
      },
      child: Container(
        margin: EdgeInsets.only(top: 13.w),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            GestureDetector(
              child: Container(
                color: RikiLoginColors.app_transparent,
                padding: EdgeInsets.all(5.w),
                child: ImageUtil.loadAssetImage(widget.isAgreement ? R.libAssetsIcLoginAgreeProxy : R.libAssetsIcLoginAgreeNoselect, width: 14.w, height: 14.w,package: RikiLogin.PACKAGE),
              ),
              onTap: () => _onPressAgreement(),
            ),
            Expanded(
              child: Text.rich(
                TextSpan(
                  // style: TextStyle(color: Colors.black, fontSize: 12.sp),
                  children: <InlineSpan>[
                    WidgetSpan(
                      child: Container(
                        // color: Colors.blue,
                        padding: padding,
                        child: Text(
                          RikiLoginTextContent.comment_login_agree_text,
                          style: TextStyle(color: Color(0xFF999999), fontSize: 10.sp, height: height),
                        ),
                      ),
                    ),
                    WidgetSpan(
                      child: GestureDetector(
                        behavior: HitTestBehavior.translucent,
                        onTap: () {
                          //隐私协议
                          RikiWebView.instance.enter(
                            context,
                            RikiWebViewConfig(
                              RikiLogin().h5Url + HtmlRoute.service_agreement,
                              title: RikiLoginTextContent.login_privacy_user_agreement,
                            ),
                          );
                        },
                        child: Container(
                          // color: Colors.red,
                          padding: padding,
                          child: Text(
                            RikiLoginTextContent.login_privacy_user_agreement,
                            style: TextStyle(color: Color(0xFF35C4C4), fontSize: 10.sp, height: height),
                          ),
                        ),
                      ),
                    ),
                    WidgetSpan(
                      child: GestureDetector(
                        behavior: HitTestBehavior.translucent,
                        onTap: () {
                          //隐私协议
                          //隐私协议
                          RikiWebView.instance.enter(
                            context,
                            RikiWebViewConfig(
                              RikiLogin().h5Url + HtmlRoute.service_agreement_privacy,
                              title: RikiLoginTextContent.login_privacy_agreement,
                            ),
                          );
                        },
                        child: Container(
                          // color: Colors.green,
                          padding: padding,
                          child: Text(
                            RikiLoginTextContent.login_privacy_agreement,
                            style: TextStyle(color: Color(0xFF35C4C4), fontSize: 10.sp, height: height),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  //点击协议
  _onPressAgreement() {
    if (mounted)
      setState(() {
        widget.isAgreement = !widget.isAgreement;
        RikiLogin.instance.refreshAgreeAgreement(widget.isAgreement);
        this.widget.isAgreementFun(widget.isAgreement);
      });
  }
}

typedef IsAgreementFun = void Function(bool isAgreement);
